package db.type;

import utility.Utility;


public class Column {
	
	private Table table; 
	private String name;
	private String type;
	private boolean isPk = false;
	private String comment = "-";
	private long length = -1; 
	private boolean isNullable = false; 
	
	public Column() {
		
	}
	
	public Column(Table table, String columnName) {
		this.table = table;
		this.name = columnName;
	}
	
	public long getLength() {
		return length;
	}
	public void setLength(long length) {
		this.length = length;
	}
	public String getComment() {
		return comment;
	}
	public void setComment(String comment) {
		this.comment = comment;
	}
	public String getName() {
		return name;
	}
	public void setName(String name) {
		this.name = name;
	}
	public String getType() {
		return type;
	}
	public void setType(String type) {
		this.type = type;
	}
	
	public String getJavaName() {
		return Utility.createJavaNameFromFieldName(false, getName());
	}
	
	public String getJavaNameFirstUpperCase() {
		String name = Utility.createJavaNameFromFieldName(false, getName());
		
		return name.substring(0, 1).toUpperCase()
			+ name.substring(1, name.length());
	}
	
	public String getJavaTyp() {
		
		String result = "unknown Typ [" + getType() + "] please add in Column";
		
		if (getType().equalsIgnoreCase("VARCHAR2")) {
			result = "String";
		}
		
		if (getType().equalsIgnoreCase("varchar")) {
			result = "String";
		}
		if (getType().equalsIgnoreCase("clob")) {
			result = "String";
		}
		if (getType().equalsIgnoreCase("int")) {
			result = "Long";
		}
		if (getType().equalsIgnoreCase("long")) {
			result = "Long";
		}
		if (getType().equalsIgnoreCase("bigint")) {
			result = "Long";
		}
		if (getType().equalsIgnoreCase("timestamp")) {
			result = "Timestamp";
		}
		
		if (getType().equalsIgnoreCase("longtext")) {
			result = "String";
		}
		
		if (getType().equalsIgnoreCase("char")) {
			result = "String";
		}
		
		if (getType().equalsIgnoreCase("date")) {
			result = "Date";
		}
		
		if (getType().equalsIgnoreCase("number")) {
			result = "Long";
		}
		
		if (getType().equalsIgnoreCase("timestamp(6)")) {
			result = "Timestamp";
		}
		
		if (getType().equalsIgnoreCase("blob")) {
			result = "BLOB";
		}
		
		return result;
	}
	
	public String getJavaGetter() {
		return "get" + getJavaName().substring(0,1).toUpperCase() + getJavaName().substring(1, getJavaName().length());
	}
	
	public String getJavaEquals() {
		return "equals" + getJavaName().substring(0,1).toUpperCase() + getJavaName().substring(1, getJavaName().length());
	}
	
	public String getJavaSetter() {
		return "set" + getJavaName().substring(0,1).toUpperCase() + getJavaName().substring(1, getJavaName().length());
	}
	public boolean isPk() {
		return isPk;
	}
	public void setPk(boolean isPk) {
		this.isPk = isPk;
	}
	public boolean isNullable() {
		return isNullable;
	}
	public void setNullable(boolean isNullable) {
		this.isNullable = isNullable;
	}
	
	public Table getTable() {
		return table;
	}
	public void setTable(Table table) {
		this.table = table;
	}
	
	public String getFullName() {
		return getTable().getFullName() + ":" + getName();
	}

}
